package org.come.login;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.come.view.View;

/**
 * @author HGC<br>
 * @time 2020年4月15日 上午11:32:16<br>
 * @class 类名:BindAccountView 绑定账号View<br>
 */
public class BindAccountView extends View{
    private SpriteBtn btnYes,//确认按钮
        Btnno,
        backImg;
    private JLabel labMsgTip;// 放置提示信息
    private JTextField textAcc;// 账号
    private JPasswordField textPwd,// 密码
            textScode;// 再次输入密码
    private LoginJpanel loginJpanel;
    public BindAccountView(LoginJpanel loginJpanel) {
        this.loginJpanel = loginJpanel;
        this.setPreferredSize(new Dimension(530, 168));
        this.setLayout(null);
        backImg = new SpriteBtn("resource/NewUi/绑定账号", 0, 0, false);
        backImg.setBounds(0, 0, 424, 278);
        this.add(backImg);

        // 放置提示信息
        labMsgTip = new JLabel();
        labMsgTip.setBounds(60, 45, 300, 30);
        labMsgTip.setFont(new Font("楷体", 1, 16));
        labMsgTip.setForeground(Color.red);
        this.add(labMsgTip);
     // 账号
        textAcc = new JTextField();
        textAcc.setBounds(138, 88, 245, 23);
        textAcc.setOpaque(false);
        textAcc.setBorder(BorderFactory.createEmptyBorder());
        textAcc.setForeground(Color.WHITE);
        textAcc.setFont(new Font("宋体", 0, 14));
        textAcc.setText("请输入您要绑定的账号");
        textAcc.setCaretColor(Color.WHITE);// 设置光标颜色为白色
        textAcc.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void removeUpdate(DocumentEvent e) {
                String str = textAcc.getText();
                if (!str.matches("[\u4e00-\u9fa5]+")) {
                    labMsgTip.setText("");
                } else {
                    labMsgTip.setText("账号不能包含中文！");
                }
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                String str = textAcc.getText();
                if (!str.matches("[\u4e00-\u9fa5]+")) {
                    labMsgTip.setText("");
                } else {
                    labMsgTip.setText("账号不能包含中文！");
                }
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }
        });
        textAcc.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (textAcc.getText() == null) {
                    labMsgTip.setText("请输入您要绑定的账号！");
                } else if("".equals(textAcc.getText())) {
                    labMsgTip.setText("请输入您要绑定的账号！");
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {
            }
        });
        textAcc.addFocusListener(new FocusListener() {
            @Override
            public void focusLost(FocusEvent e) {
                if (textAcc.getText().matches("[\u4e00-\u9fa5]+")) {
                    textAcc.setText("");
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
                textAcc.setText("");
            }
        });
        this.add(textAcc);
        // 密码
        textPwd = new JPasswordField();
        textPwd.setBounds(138, 127, 245, 23);
        textPwd.setOpaque(false);
        textPwd.setBorder(BorderFactory.createEmptyBorder());
        textPwd.setForeground(Color.WHITE);
        textPwd.setFont(new Font("宋体", 0, 14));
        textPwd.setCaretColor(Color.WHITE);// 设置光标颜色为白色
        textPwd.setEchoChar('*');// 设置以‘ * ’来显示密码信息
        textPwd.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (textPwd.getText() == null) {
                    labMsgTip.setText("请输入您绑定账号的密码！");
                } else {
                    labMsgTip.setText("");
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {
            }
        });
        this.add(textPwd);
        // 再次输入密码
        textScode = new JPasswordField();
        textScode.setBounds(138, 166, 245, 23);
        textScode.setOpaque(false);
        textScode.setBorder(BorderFactory.createEmptyBorder());
        textScode.setForeground(Color.WHITE);
        textScode.setFont(new Font("宋体", 0, 14));
        textScode.setCaretColor(Color.WHITE);// 设置光标颜色为白色
        textScode.setEchoChar('*');// 设置以‘ * ’来显示密码信息
        textScode.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void removeUpdate(DocumentEvent e) {
                String str = textScode.getText();
                if (str.matches("[0-9a-zA-Z]*")) {
                    labMsgTip.setText("");
                } else {
                    labMsgTip.setText("安全码不能包含中文或特殊字符！");
                }
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                String str = textScode.getText();
                if (str.matches("[0-9a-zA-Z]*")) {
                    labMsgTip.setText("");
                } else {
                    labMsgTip.setText("安全码不能包含中文或特殊字符！");
                }
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }
        });
        textScode.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
                if (textScode.getText() == null) {
                    labMsgTip.setText("请输入您绑定账号的安全码！");
                } else {
                    labMsgTip.setText("");
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {
            }
        });
        this.add(textScode);

        btnYes = new SpriteBtn("resource/NewUi/按钮_确定3", 20, 205, false);
        btnYes.setBounds(20, 205, 192, 52);
        btnYes.addMouseListener(new LoginMouslisten(10, btnYes, loginJpanel));
        this.add(btnYes);
        Btnno = new SpriteBtn("resource/NewUi/按钮_取消4", 220, 213, false);
        Btnno.setBounds(220, 213, 159, 44);
        Btnno.addMouseListener(new LoginMouslisten(11, Btnno, loginJpanel));
        this.add(Btnno);
    }
    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        backImg.draw(g);
        btnYes.draw(g);
        Btnno.draw(g);
    }
	public JTextField getTextAcc() {
		return textAcc;
	}
	public void setTextAcc(JTextField textAcc) {
		this.textAcc = textAcc;
	}
	public JPasswordField getTextPwd() {
		return textPwd;
	}
	public void setTextPwd(JPasswordField textPwd) {
		this.textPwd = textPwd;
	}
	public JPasswordField getTextScode() {
		return textScode;
	}
	public void setTextScode(JPasswordField textScode) {
		this.textScode = textScode;
	}
    public SpriteBtn getBtnYes() {
        return btnYes;
    }
    public void setBtnYes(SpriteBtn btnYes) {
        this.btnYes = btnYes;
    }
    public SpriteBtn getBtnno() {
        return Btnno;
    }
    public void setBtnno(SpriteBtn btnno) {
        Btnno = btnno;
    }
    public SpriteBtn getBackImg() {
        return backImg;
    }
    public void setBackImg(SpriteBtn backImg) {
        this.backImg = backImg;
    }
    public JLabel getLabMsgTip() {
        return labMsgTip;
    }
    public void setLabMsgTip(JLabel labMsgTip) {
        this.labMsgTip = labMsgTip;
    }
    public LoginJpanel getLoginJpanel() {
        return loginJpanel;
    }
    public void setLoginJpanel(LoginJpanel loginJpanel) {
        this.loginJpanel = loginJpanel;
    }
    
    
}
